﻿@using KC.MVC.Core.Constants
@using KC.Web.Account.Constants
@model KC.DTO.Account.MenuNodeDTO

<form class="easyui-form" method="post" data-options="novalidate:true" id="saveform" action="@Url.Action(ActionName.Menu.SaveMenu, ControllerName.Menu)">
    @Html.AntiForgeryToken()
    @Html.HiddenFor(model => model.id)
    @Html.HiddenFor(model => model.ApplicationId)
    @Html.HiddenFor(model => model.ApplicationName)
    @Html.HiddenFor(model => model.IsDeleted)
    @Html.HiddenFor(model => model.CreatedBy)
    @Html.HiddenFor(model => model.CreatedDate)
    @Html.HiddenFor(model => model.ModifiedBy)
    @Html.HiddenFor(model => model.ModifiedDate)
    <style>
        span.textbox.combo.textbox-readonly input.textbox-text.validatebox-text.validatebox-readonly.validatebox-f {
            background-color: darkgrey;
        }
    </style>
    <table class="dialog-form-table">
        <tbody>
            <tr id="tdTenantType" style="display: none;">
                <td><label class="required"></label><label for="TenantType">系统类型：</label></td>
                <td>@Html.DropDownList("TenantType", (IEnumerable<SelectListItem>)ViewBag.TenantTypeList, new { @id = "TenantType", @class = "easyui-combobox", @style = "width: 200px;height:26px;" })</td>
            </tr>
            <tr>
                <td><label class="required">*</label><label for="ParentId">父节点：</label></td>
                <td>
                    <input id="ParentId" name="ParentId" class="easyui-combotree" value="@(null != Model ? Model.ParentId : null)" style="width: 200px; height: 26px;" data-options="required:true">
                </td>
            </tr>
            <tr>
                <td><label class="required">*</label><label for="text">名称：</label></td>
                <td><input id="text" name="text" class="easyui-validatebox textbox" data-options="required:true,width:200,validType:'length[2,15]'" value="@(null != Model ? Model.text : string.Empty)" /></td>
            </tr>
            <tr>
                <td><label class="required">*</label><label for="Version">版本类型(可多选)：</label></td>
                <td>@Html.DropDownList("Version", (IEnumerable<SelectListItem>)ViewBag.SystemVersionList, new { @id = "Version", @class = "easyui-combobox", @style = "width: 200px;height:26px;" })</td>
            </tr>
            <tr>
                <td><label class="required">*</label><label for="AreaName">AreaName名称：</label></td>
                <td><input id="AreaName" name="AreaName" class="easyui-validatebox textbox" data-options="required:true,width:200,validType:'length[3,64]'" style="background-color: darkgrey" value="@(null != Model ? Model.AreaName : string.Empty)" /></td>
            </tr>
            <tr>
                <td><label class="required">*</label><label for="ControllerName">Controller名称：</label></td>
                <td><input id="ControllerName" name="ControllerName" class="easyui-validatebox textbox" data-options="required:true,width:200,validType:'length[3,64]'" style="background-color: darkgrey" value="@(null != Model ? Model.ControllerName : string.Empty)" /></td>
            </tr>
            <tr>
                <td><label class="required">*</label><label for="ActionName">Action名称：</label></td>
                <td><input id="ActionName" name="ActionName" class="easyui-validatebox textbox" data-options="required:true,width:200,validType:'length[3,64]'" style="background-color: darkgrey" value="@(null != Model ? Model.ActionName : string.Empty)" /></td>
            </tr>
            <tr>
                <td><label class="required">*</label><label for="SmallIcon">小图标:</label></td>
                <td>
                    <input id="SmallIcon" name="SmallIcon" class="easyui-textbox textbox" data-options="required:true,width:200,height:26" value="@(null == Model ? "" : Model.SmallIcon)">
                </td>
            </tr>
            <tr>
                <td><label class="required">*</label><label for="Index">排序:</label></td>
                <td><input id="Index" name="Index" class="easyui-numberspinner textbox" data-options="required:true,width:200,height:26,min:1,max:100" value="@(null != Model ? Model.Index : 0)"></td>
            </tr>
            <tr>
                <td><label for="Description">描述:</label></td>
                <td>
                    <input class="easyui-textbox" id="Description" name="Description" data-options="multiline:true" value="@(null != Model ? Model.Description : "")" style="height: 60px; width: 195px;">
                </td>
            </tr>
        </tbody>
    </table>
</form>
<script>
    $(function () {
        $('.textbox').bind('blur', function () {
            $(this).validatebox('enableValidation').validatebox('validate');
        });
        $('#TenantType').combobox();

        $('#TenantType').combobox({
            onSelect: function(record) {
                var url = '@Url.Action(ActionName.Menu.LoadMenuTree,ControllerName.Menu)?tally=' + record.value;
                $('#ParentId').combotree({
                    url: url,
                    required: true
                });
            }
        });

        $('#ControllerName').validatebox({ });
        $('#ActionName').validatebox({});

        $('#Version').combobox({
            required: true,
            multiple: true,
            formatter: function (row) {
                var opts = $(this).combobox('options');
                return '<input type="checkbox" class="combobox-checkbox">' + row[opts.textField];
            },
            onLoadSuccess: function (node, data) {
                $(this).combobox('setValues', [@ViewBag.SelectedVersionIds]);

                var opts = $(this).combobox('options');
                var target = this;
                var values = $(target).combobox('getValues');
                $.map(values, function (value) {
                    var el = opts.finder.getEl(target, value);
                    el.find('input.combobox-checkbox')._propAttr('checked', true);
                });
            },
            onSelect: function (row) {
                console.log(row)
                var opts = $(this).combobox('options');
                var el = opts.finder.getEl(this, row[opts.valueField]);
                el.find('input.combobox-checkbox')._propAttr('checked', true);
            },
            onUnselect: function (row) {
                var opts = $(this).combobox('options');
                var el = opts.finder.getEl(this, row[opts.valueField]);
                el.find('input.combobox-checkbox')._propAttr('checked', false);
            }
        });

        $("#TenantType").combobox('setValue', @ViewBag.SelectedTenantType);
    });

</script>